/*
 * Copyright 2018-present KunMinX
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.nsgf.library.ui.adapter;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.DiffUtil;

import com.nsgf.library.data.bean.ClockInBean;
import com.nsgf.library.data.bean.DeviceOpeningBean;
import com.nsgf.library.data.bean.HomeDeviceOpeningBean;
import com.nsgf.library.data.bean.LibraryInfo;
import com.nsgf.library.data.bean.MessageBean;
import com.nsgf.library.data.bean.TestAlbum;
import com.nsgf.library.data.bean.VideoListBean;
import com.nsgf.library.data.bean.WaterInfoListBean;
import com.nsgf.library.data.bean.WeatherBean;
import com.nsgf.library.data.bean.WorkOrderBean;
import com.nsgf.library.data.bean.WorkOrderDetailBean;

/**
 * Create by GC at 2024/11/19
 */
public class DiffUtils {

    private DiffUtil.ItemCallback<LibraryInfo> mLibraryInfoItemCallback;
    private DiffUtil.ItemCallback<VideoListBean.ListBean> mClockInBeanItemCallback;

    private DiffUtil.ItemCallback<TestAlbum> mTestMusicItemCallback;
    private DiffUtil.ItemCallback<MessageBean.DataBean> mMessageItemCallback;
    private DiffUtil.ItemCallback<VideoListBean.ListBean> mClockInLateBeanItemCallback;
    private DiffUtil.ItemCallback<WorkOrderBean> mWorkOrderItemCallback;
    private DiffUtil.ItemCallback<WorkOrderDetailBean.DataBean.PositionVOSBean> mWorkOrderDetailItemCallback;
    private DiffUtil.ItemCallback<WorkOrderDetailBean.DataBean.PositionVOSBean.ItemsBean> mWorkOrderDetailTaskItemCallback;
    private DiffUtil.ItemCallback<WorkOrderDetailBean.DataBean.PtWorkOrderAbnormal> mWorkOrderAbnormalItemCallback;

    private DiffUtil.ItemCallback<WeatherBean.DataBean> mWeatherCallback;
    private DiffUtil.ItemCallback<VideoListBean> mVideoListTypeItemCallback;
    private DiffUtil.ItemCallback<VideoListBean.ListBean> mVideoListItemCallback;
    private DiffUtil.ItemCallback<WaterInfoListBean.ReservoirBean> mReservoirItemCallback;
    private DiffUtil.ItemCallback<WaterInfoListBean.FlowBean> mFlowItemCallback;
    private DiffUtil.ItemCallback<DeviceOpeningBean.Devices> mHomeDeviceOpeningItemCallback;

    private DiffUtils() {
    }

    private static final DiffUtils S_DIFF_UTILS = new DiffUtils();

    public static DiffUtils getInstance() {
        return S_DIFF_UTILS;
    }

    public DiffUtil.ItemCallback<LibraryInfo> getLibraryInfoItemCallback() {
        if (mLibraryInfoItemCallback == null) {
            mLibraryInfoItemCallback = new DiffUtil.ItemCallback<LibraryInfo>() {
                @Override
                public boolean areItemsTheSame(@NonNull LibraryInfo oldItem, @NonNull LibraryInfo newItem) {
                    return oldItem.equals(newItem);
                }

                @Override
                public boolean areContentsTheSame(@NonNull LibraryInfo oldItem, @NonNull LibraryInfo newItem) {
                    return oldItem.getTitle().equals(newItem.getTitle());
                }
            };
        }
        return mLibraryInfoItemCallback;
    }

    public DiffUtil.ItemCallback<TestAlbum> getTestMusicItemCallback() {
        if (mTestMusicItemCallback == null) {
            mTestMusicItemCallback = new DiffUtil.ItemCallback<TestAlbum>() {
                @Override
                public boolean areItemsTheSame(@NonNull TestAlbum oldItem, @NonNull TestAlbum newItem) {
                    return oldItem.equals(newItem);
                }

                @Override
                public boolean areContentsTheSame(@NonNull TestAlbum oldItem, @NonNull TestAlbum newItem) {
                    return oldItem.albumMid.equals(newItem.getAlbumMid());
                }
            };
        }
        return mTestMusicItemCallback;
    }

    public DiffUtil.ItemCallback<MessageBean.DataBean> getMessageItemCallback() {
        if (mMessageItemCallback == null) {
            mMessageItemCallback = new DiffUtil.ItemCallback<MessageBean.DataBean>() {
                @Override
                public boolean areItemsTheSame(@NonNull MessageBean.DataBean oldItem, @NonNull MessageBean.DataBean newItem) {
                    return oldItem.equals(newItem);
                }

                @Override
                public boolean areContentsTheSame(@NonNull MessageBean.DataBean oldItem, @NonNull MessageBean.DataBean newItem) {
                    return oldItem.getContent().equals(newItem.getContent());
                }
            };
        }
        return mMessageItemCallback;
    }


    public DiffUtil.ItemCallback<VideoListBean.ListBean> getClockInInfoItemCallback() {
        if (mClockInBeanItemCallback == null) {
            mClockInBeanItemCallback = new DiffUtil.ItemCallback<VideoListBean.ListBean>() {
                @Override
                public boolean areItemsTheSame(@NonNull VideoListBean.ListBean oldItem, @NonNull VideoListBean.ListBean newItem) {
                    return oldItem.equals(newItem);
                }

                @Override
                public boolean areContentsTheSame(@NonNull VideoListBean.ListBean oldItem, @NonNull VideoListBean.ListBean newItem) {
                    return oldItem.getDeviceName().equals(newItem.getDeviceName());
                }
            };
        }
        return mClockInBeanItemCallback;
    }

    public DiffUtil.ItemCallback<VideoListBean> getVideoListCallback() {
        if (mVideoListTypeItemCallback == null) {
            mVideoListTypeItemCallback = new DiffUtil.ItemCallback<VideoListBean>() {
                @Override
                public boolean areItemsTheSame(@NonNull VideoListBean oldItem, @NonNull VideoListBean newItem) {
                    return oldItem.equals(newItem);
                }

                @Override
                public boolean areContentsTheSame(@NonNull VideoListBean oldItem, @NonNull VideoListBean newItem) {
                    return oldItem.getId().equals(newItem.getId());
                }
            };
        }
        return mVideoListTypeItemCallback;
    }

    public DiffUtil.ItemCallback<VideoListBean.ListBean> getVideoListItemCallback() {
        if (mVideoListItemCallback == null) {
            mVideoListItemCallback = new DiffUtil.ItemCallback<VideoListBean.ListBean>() {
                @Override
                public boolean areItemsTheSame(@NonNull VideoListBean.ListBean oldItem, @NonNull VideoListBean.ListBean newItem) {
                    return oldItem.equals(newItem);
                }

                @Override
                public boolean areContentsTheSame(@NonNull VideoListBean.ListBean oldItem, @NonNull VideoListBean.ListBean newItem) {
                    return oldItem.getFacilityTypeDesc().equals(newItem.getFacilityTypeDesc());
                }
            };
        }
        return mVideoListItemCallback;
    }


    public DiffUtil.ItemCallback<VideoListBean.ListBean> getClockInInfoLateItemCallback() {
        if (mClockInLateBeanItemCallback == null) {
            mClockInLateBeanItemCallback = new DiffUtil.ItemCallback<VideoListBean.ListBean>() {
                @Override
                public boolean areItemsTheSame(@NonNull VideoListBean.ListBean oldItem, @NonNull VideoListBean.ListBean newItem) {
                    return oldItem.equals(newItem);
                }

                @Override
                public boolean areContentsTheSame(@NonNull VideoListBean.ListBean oldItem, @NonNull VideoListBean.ListBean newItem) {
                    return oldItem.getFacilityName().equals(newItem.getFacilityName());
                }
            };
        }
        return mClockInLateBeanItemCallback;
    }


    public DiffUtil.ItemCallback<WorkOrderBean> getmWorkOrderItemCallback() {
        if (mWorkOrderItemCallback == null) {
            mWorkOrderItemCallback = new DiffUtil.ItemCallback<WorkOrderBean>() {
                @Override
                public boolean areItemsTheSame(@NonNull WorkOrderBean oldItem, @NonNull WorkOrderBean newItem) {
                    return oldItem.equals(newItem);
                }

                @Override
                public boolean areContentsTheSame(@NonNull WorkOrderBean oldItem, @NonNull WorkOrderBean newItem) {
                    return oldItem.getOrderCode().equals(newItem.getOrderCode());
                }
            };
        }
        return mWorkOrderItemCallback;
    }

    public DiffUtil.ItemCallback<WorkOrderDetailBean.DataBean.PositionVOSBean> getmWorkOrderDetailItemCallback() {
        if (mWorkOrderDetailItemCallback == null) {
            mWorkOrderDetailItemCallback = new DiffUtil.ItemCallback<WorkOrderDetailBean.DataBean.PositionVOSBean>() {
                @Override
                public boolean areItemsTheSame(@NonNull WorkOrderDetailBean.DataBean.PositionVOSBean oldItem, @NonNull WorkOrderDetailBean.DataBean.PositionVOSBean newItem) {
                    return oldItem.equals(newItem);
                }

                @Override
                public boolean areContentsTheSame(@NonNull WorkOrderDetailBean.DataBean.PositionVOSBean oldItem, @NonNull WorkOrderDetailBean.DataBean.PositionVOSBean newItem) {
                    return oldItem.getAreaCode().equals(newItem.getAreaCode());
                }
            };
        }
        return mWorkOrderDetailItemCallback;
    }

    public DiffUtil.ItemCallback<WorkOrderDetailBean.DataBean.PositionVOSBean.ItemsBean> getmWorkOrderDetailTaskItemCallback() {
        if (mWorkOrderDetailTaskItemCallback == null) {
            mWorkOrderDetailTaskItemCallback = new DiffUtil.ItemCallback<WorkOrderDetailBean.DataBean.PositionVOSBean.ItemsBean>() {
                @Override
                public boolean areItemsTheSame(@NonNull WorkOrderDetailBean.DataBean.PositionVOSBean.ItemsBean oldItem, @NonNull WorkOrderDetailBean.DataBean.PositionVOSBean.ItemsBean newItem) {
                    return oldItem.equals(newItem);
                }

                @Override
                public boolean areContentsTheSame(@NonNull WorkOrderDetailBean.DataBean.PositionVOSBean.ItemsBean oldItem, @NonNull WorkOrderDetailBean.DataBean.PositionVOSBean.ItemsBean newItem) {
                    return oldItem.getAreaCode().equals(newItem.getAreaCode());
                }
            };
        }
        return mWorkOrderDetailTaskItemCallback;
    }


    public DiffUtil.ItemCallback<WorkOrderDetailBean.DataBean.PtWorkOrderAbnormal> getmWorkOrderAbnormalItemCallback() {
        if (mWorkOrderAbnormalItemCallback == null) {
            mWorkOrderAbnormalItemCallback = new DiffUtil.ItemCallback<WorkOrderDetailBean.DataBean.PtWorkOrderAbnormal>() {
                @Override
                public boolean areItemsTheSame(@NonNull WorkOrderDetailBean.DataBean.PtWorkOrderAbnormal oldItem,
                                               @NonNull WorkOrderDetailBean.DataBean.PtWorkOrderAbnormal newItem) {
                    return oldItem.equals(newItem);
                }

                @Override
                public boolean areContentsTheSame(@NonNull WorkOrderDetailBean.DataBean.PtWorkOrderAbnormal oldItem,
                                                  @NonNull WorkOrderDetailBean.DataBean.PtWorkOrderAbnormal newItem) {
                    return oldItem.getAreaCode().equals(newItem.getAreaCode());
                }
            };
        }
        return mWorkOrderAbnormalItemCallback;
    }

    public DiffUtil.ItemCallback<WeatherBean.DataBean> getWeatherCallbacklItemCallback() {
        if (mWeatherCallback == null) {
            mWeatherCallback = new DiffUtil.ItemCallback<WeatherBean.DataBean>() {
                @Override
                public boolean areItemsTheSame(@NonNull WeatherBean.DataBean oldItem,
                                               @NonNull WeatherBean.DataBean newItem) {
                    return oldItem.equals(newItem);
                }

                @Override
                public boolean areContentsTheSame(@NonNull WeatherBean.DataBean oldItem,
                                                  @NonNull WeatherBean.DataBean newItem) {
                    return oldItem.getDictId().equals(newItem.getDictId());
                }
            };
        }
        return mWeatherCallback;
    }

    public DiffUtil.ItemCallback<WaterInfoListBean.ReservoirBean> getReservoirItemCallback() {
        if (mReservoirItemCallback == null) {
            mReservoirItemCallback = new DiffUtil.ItemCallback<WaterInfoListBean.ReservoirBean>() {
                @Override
                public boolean areItemsTheSame(@NonNull WaterInfoListBean.ReservoirBean oldItem,
                                               @NonNull WaterInfoListBean.ReservoirBean newItem) {
                    return oldItem.equals(newItem);
                }

                @Override
                public boolean areContentsTheSame(@NonNull WaterInfoListBean.ReservoirBean oldItem,
                                                  @NonNull WaterInfoListBean.ReservoirBean newItem) {
                    return oldItem.getFacilityCode().equals(newItem.getFacilityCode());
                }
            };
        }
        return mReservoirItemCallback;
    }

    public DiffUtil.ItemCallback<WaterInfoListBean.FlowBean> getFlowItemCallback() {
        if (mFlowItemCallback == null) {
            mFlowItemCallback = new DiffUtil.ItemCallback<WaterInfoListBean.FlowBean>() {
                @Override
                public boolean areItemsTheSame(@NonNull WaterInfoListBean.FlowBean oldItem,
                                               @NonNull WaterInfoListBean.FlowBean newItem) {
                    return oldItem.equals(newItem);
                }

                @Override
                public boolean areContentsTheSame(@NonNull WaterInfoListBean.FlowBean oldItem,
                                                  @NonNull WaterInfoListBean.FlowBean newItem) {
                    return oldItem.getFacilityCode().equals(newItem.getFacilityCode());
                }
            };
        }
        return mFlowItemCallback;
    }

    public DiffUtil.ItemCallback<DeviceOpeningBean.Devices> getHomeDeviceOpeningItemCallback() {
        if (mHomeDeviceOpeningItemCallback == null) {
            mHomeDeviceOpeningItemCallback = new DiffUtil.ItemCallback<DeviceOpeningBean.Devices>() {
                @Override
                public boolean areItemsTheSame(@NonNull DeviceOpeningBean.Devices oldItem,
                                               @NonNull DeviceOpeningBean.Devices newItem) {
                    return oldItem.getDeviceCode() != null && oldItem.getDeviceCode().equals(newItem.getDeviceCode());
                }

                @Override
                public boolean areContentsTheSame(@NonNull DeviceOpeningBean.Devices oldItem,
                                                  @NonNull DeviceOpeningBean.Devices newItem) {
                    return (oldItem.getDeviceCode() != null ? oldItem.getDeviceCode().equals(newItem.getDeviceCode()) : newItem.getDeviceCode() == null) &&
                            (oldItem.getDuration() != null ? oldItem.getDuration().equals(newItem.getDuration()) : newItem.getDuration() == null);
                }
            };
        }
        return mHomeDeviceOpeningItemCallback;
    }


}
